package com.bstek.bdf4.investigate;

import com.bstek.bdf4.investigate.dao.CategoryDao;
import com.bstek.bdf4.investigate.entity.Category;
import com.bstek.bdf4.investigate.entity.Investigate;
import com.bstek.bdf4.investigate.entity.WriteInvestigate;
import com.bstek.bdf4.investigate.service.CategoryService;
import com.bstek.bdf4.investigate.service.InvestigateService;
import com.bstek.bdf4.investigate.service.WriteInvestigateService;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.data.provider.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Map;

@Component
public class WriteInvestigateProvider {
    @Autowired
    private WriteInvestigateService writeInvestigateService;
    @Autowired
    private CategoryService categoryService;

    @Autowired
    private InvestigateService investigateService;

    @DataProvider
    public void getByPage(Page<WriteInvestigate> page, Map<String, Object> params) {
        writeInvestigateService.getByPage(page,params);
    }

    @DataResolver
    @Transactional
    public void save(Collection<WriteInvestigate> writeInvestigates, String type) {
        writeInvestigateService.save(writeInvestigates,type);
    }
    @DataProvider
    public Collection<Category> getCategoryById(Long id) {
        return categoryService.getCategoryById(id);
    }

    @DataProvider
    public Collection<Category> getTopCategories() {
        return categoryService.getTopAll();
    }

    @DataProvider
    public Collection<Investigate> getInvestigateByCategoryId(Long id) {
        return investigateService.getInvestigateByCategoryId(id);
    }
}
